import 'dart:convert' as convert;

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_module/common/base/base_page.dart';
import 'package:flutter_module/common/extensions/cached_network_image_extension.dart';
import 'package:flutter_module/common/widget/video/video_player_dialog.dart';
import 'package:flutter_module/page/cooperation/widgets/cooperation_title_content_container.dart';

/// Create by kyluzoi
/// Date: 2021-08-20
///
/// Description: 服务商简介 item

class CooperationIntroItem extends BaseStatelessWidget {
  final TextStyle? contentStyle;
  final TextStyle? titleStyle;
  final String? content;
  final String? videoUrl;
  final String? videoCover; // 视频封面

  const CooperationIntroItem({
    Key? key,
    this.videoUrl,
    this.titleStyle,
    this.videoCover,
    this.contentStyle,
    this.content,
  }) : super(key: key);

  @override
  Widget createView(BuildContext context) {
    print("videourl:$videoUrl");
    return CooperationTitleContainer(
      title: "服务商简介",
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            if (videoUrl != null) ...[
              _imagePlay,
              SizedBox(
                width: 10,
              ),
            ],
            Expanded(
                child: Text(
              content ?? "",
              style: contentStyle,
              maxLines: 4,
              overflow: TextOverflow.ellipsis,
            ))
          ],
        )
      ],
    );
  }

  get _imagePlay => InkWell(
        onTap: () {
          String url;
          try {
            url = convert.jsonDecode(videoUrl ?? "")["url"];
          } catch (e) {
            url = videoUrl ?? "";
          }
          VideoPlayerDialog.show(
            videoUrl: url,
            videoCover: videoCover,
          );
        },
        child: Stack(
          alignment: Alignment.center,
          children: [
            Container(
                height: 75,
                width: 120,
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(8),
                  child:
                      YFNetworkImage(fit: BoxFit.cover, resource: videoCover),
                )),
            Icon(
              Icons.play_circle_fill_rounded,
              size: 40,
              color: Color(0xDC838387),
            )
          ],
        ),
      );
}
